package cn.seven;

import java.util.HashMap;

/**
 * create by 张天笑, 2017/10/23 22:06
 */
public class Sky<T> extends HashMap {

    private static final String ok = "1";
    private static final String no = "0";

    public Sky ok() {
        put("code", ok);
        return this;
    }

    public Sky no() {
        put("code", no);
        return this;
    }

    public Sky msg(String msg) {
        put("msg", msg);
        return this;
    }

    public Sky data(Object data) {
        put("data", data);
        return this;
    }

    public Sky set(String key, Object value) {
        put(key, value);
        return this;
    }

    public Sky(int code) {
        put("code", code);
    }

    public Sky(int code, String msg) {
        msg(msg).put("code", code);
    }

    public Sky(int code, Object data) {
        put("code", code);
        put("data", data);
    }

    public Sky(int code, String msg, Object data) {
        data(data).msg(msg).put("code", code);
    }


    public static Sky By(int code, String msg) {
        return new Sky(code, msg);
    }

    public static Sky By(int code, Object msg) {
        return new Sky(code, msg);
    }

    public static void throwExp(String... args) throws Exception {
        throw new Exception(args.length == 0 ? "???" : args[1]);
    }
}